//
//  main.c
//  C_3 字符串原理
//
//  Created by Robin on 16/3/16.
//  Copyright © 2016年 cnbm. All rights reserved.
//

#include <stdio.h>
#include <string.h> // 字符串标准库

char track[][80] = {"I left my heart in Harvard Med School",
    "NewYork NewYork,A wonderful Town",
    "Dancing With Dark",
    "From here to maternity",
    "The girl from china"
};

void print_reverse(char *str);

char *find_track(char search_for[]);

int main(int argc, const char * argv[]) {
    //strchr(<#const char *#>, <#int#>)             在字符串中查找字符
    //strcmp(<#const char *#>, <#const char *#>)    比较字符串
    //strcpy(<#char *#>, <#const char *#>)          复制字符串
    //strcat(<#char *#>, <#const char *#>)          连接字符串
    //strlen(<#const char *#>)                   返回字符串的长度
    //strstr(<#const char *#>, <#const char *#>)    在字符串中查找字符串
    
    
    puts("请输入歌名:");
    
    char search_for[80];
    fgets(search_for, 80, stdin);
    
    search_for[strlen(search_for)-1] = '\0';
    
    char *songName = find_track(search_for);
    
    printf("你是要点 : %s\n",songName);
    
    char *testStr = "abc";
    
    print_reverse(testStr);
    
    
//    char *str0 = "Robin";
//    char *str1 = "Guo";
    
    
//    char s0[] = "dynamic fun!";
//    char s1[] = "fun";
//    
//    if (strstr(s0, s1)) {
//        printf("在字符串s0%s中找到%s\n",s0,s1);
//    }
    
    // 填字游戏
    char *juice[] = {"dragonfruit",
                     "waterberry",
                     "sharonfruit",
                     "uglifruit",
                     "rumberry",
                     "kiwifruit",
                     "mulberry",
                     "strawberry",
                     "blueberry",
                     "blackberry",
                     "starfruit"
                     };
    
    puts(*(juice+1));
    puts(*juice+2);
    puts(juice[2]);
    
    return 0;
}

void print_reverse(char *s){
    
    size_t len = strlen(s);
    char *c = s+len-1;
    
    while (c >= s) {
        
        printf("%c",*c);
        c -= 1;
    }
    
    puts("");
}

char *find_track (char search_for[]){
    
    for (int i=0; i<5; i++) {
        //char songName[] = track[i];
        if (strstr(track[i], search_for)) {
            return track[i];
        }
    }
    
    return "Sorry,No that song";
}
